﻿using ARchGL.Platform.Authorization.Users;
using ARchGL.Platform.Core;
using ARchGL.Platform.Dtos;
using ARchGL.Platform.EntityFrameworkCore;
using ARchGL.Platform.Juneng;
using System;
using System.Collections.Generic;
using System.Text;

namespace ARchGL.Platform.Tests.TestDatas
{
    public class TestJunengBuilder
    {
        private readonly HostDbContext _context;
        private readonly int _tenantId;

        public TestJunengBuilder(HostDbContext context, int tenantId)
        {
            _context = context;
            _tenantId = tenantId;
        }

        public void Creat()
        {
            CreatNotices();
            CreatNoticeUser();
            CreatDrawings();
            CreatProjects();
            CreateProjectModels();
            CreatFiles();
            CreatFolders();

            CreateSecurityCheckItems();
            CreateSecurityChecks();
        }

        private void CreatNotices()
        {
            var entity = new Notices
            {
                Id = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0001"),
                Title = "test",
                Content = "test",
                Type = 1,
                Status = 1
            };

            _context.Notices.Add(entity);
            _context.SaveChanges();
        }
        private void CreatNoticeUser()
        {
            var entity = new NoticesUsers
            {
                UserId = Guid.Parse("00000000-0000-0000-0000-000000000001"),
                NoticeId = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0001"),
                Status = 2
            };

            _context.NoticesUser.Add(entity);
            _context.SaveChanges();
        }
        private void CreatDrawings()
        {
            var entity = new ProjectDrawings
            {
                Id = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0003"),
                ProjectId = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0002"),
                Name = "Test",
                //ModelId = Guid.Empty
            };

            _context.ProjectDrawings.Add(entity);
            _context.SaveChanges();
        }
        private void CreatProjects()
        {
            var entity = new Projects
            {
                Id = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0002"),
                TenantId = 1,
                Type = EnumProjectType.公路工程,
                Name = "Test"
            };

            _context.Projects.Add(entity);
            _context.SaveChanges();
        }
        private void CreateProjectModels()
        {
            var entity = new ProjectModels
            {
                Id = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0004"),
                ProjectId = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0002"),
                Name = "Test",
                ImageUrl = "Test",
                CreatorUserName = "Test",
                Path = "Test"
            };

            _context.ProjectModels.Add(entity);
            _context.SaveChanges();
        }
        private void CreatFiles()
        {
            var entity = new DocumentLibrarys
            {
                Id = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0005"),
                FileId = Guid.Parse("69092d98-e4eb-4088-8f6e-000000000001"),
                Name = "FileTest",
                Size = 1,
                CreatorUserId = Guid.Parse("00000000-0000-0000-0000-000000000001"),
                Url = "FileTest"
            };

            _context.DocumentLibrarys.Add(entity);
            _context.SaveChanges();
        }
        private void CreatFolders()
        {
            var entity = new DocumentLibrarys
            {
                Id = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0006"),
                FileId = null,
                Name = "FolderTest",
                Size = 1,
                CreatorUserId = Guid.Parse("00000000-0000-0000-0000-000000000001"),
                Url = "FolderTest"
            };

            _context.DocumentLibrarys.Add(entity);
            _context.SaveChanges();
        }

        private void CreateSecurityCheckItems()
        {
            var entity = new SecurityCheckItems//检查项
            {
                Id = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0007"),
                ProjectId = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0002"),
                Name = "SecurityCheckItemsTest1",
                Type = EnumCheckItemType.检查项,
            };

            _context.SecurityCheckItems.Add(entity);
            _context.SaveChanges();

            entity = new SecurityCheckItems//检查性质
            {
                Id = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0008"),
                ProjectId = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0002"),
                Name = "SecurityCheckItemsTest2",
                Type = EnumCheckItemType.检查性质,
            };

            _context.SecurityCheckItems.Add(entity);
            _context.SaveChanges();
        }

        private void CreateSecurityChecks()
        {
            var entity = new SecurityChecks
            {
                Id = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0007"),
                ProjectId = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0002"),
                Content = "SecurityChecksTest",
                Result = "SecurityChecks ItemContent Test",
                CheckItemId = Guid.Parse("69092d98-e4eb-4088-8f6e-f332ba3f0002"),
                CreatorUserId = Guid.Parse("00000000-0000-0000-0000-000000000001"),
                //SecurityChecksItemsArray = "[\"69092d98-e4eb-4088-8f6e-f332ba3f0007\"]",
                SecurityChecksPropertysArray = "[\"69092d98-e4eb-4088-8f6e-f332ba3f0008\"]",
                CheckDate = DateTime.Parse("2019-04-01"),
                //OrganizationUnitId = 1,
                NotifyUsersArray = "[1,2]",
                //CorrectOrder = "干净整洁",
                CorrectDate = DateTime.Parse("2019-05-01"),
                CorrectContent = "干净整洁，整改要求",
                CCUsersArray = "[1]",
                Status = EnumCheckAndFeedbackStatus.整改中
            };

            _context.SecurityChecks.Add(entity);
            _context.SaveChanges();
        }
    }
}
